﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLDC.Common.Estate;
using ZLDC.Topo.Model.Estate;

namespace ZLDC.Estate.PM
{
    public partial class HousingCheck : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string station = this.info.m_sStation;
                string deptid = this.info.m_sDeptID;
                string deptname = this.info.m_sDeptName;
                if ((_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station)) || ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部盘源"))
                {
                    divCheck.Visible = true;
                    hStation.Value = station;
                }
                markuid.Value = _Utility.GetInfoBySession().m_sUserID;
            }
        }

        /// <summary>
        /// 转到当前盘(指定开盘人)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btToPty_Click(object sender, System.EventArgs e)
        {
            int id = _Convert.ToInt(hID.Value, 0);

            if (id <= 0)
            {
                _JavaScript.Alert(this.Page, "请先选择您要操作的盘源");
                return;
            }

            string userNoAndName = tbMakeUser.Text;      // 工号及名称

            if (userNoAndName.Trim().Equals(""))
            {
                _JavaScript.Alert(this.Page, "开盘人不能为空");
                return;
            }

            string userName = string.Empty; // 姓名
            string userNo = string.Empty;   // 工号
            int userId = 0;                 // 楼盘系统用户ID
            _Utility.GetUserNoAndUserName(userNoAndName.Trim(), out userName, out userNo);
            userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);

            // 更新开盘人及开盘人部门信息
            UserInfo info = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserID(userId);

            int deptid = info.Dept_id;
            string deptname = info.DeptName;
            int userid = info.Id;
            string username = info.Name;

            ZLDC.Topo.BLL.Estate.HousingBLL.HousingStatusPty(id, userid, username, deptid, deptname);
            
            int status = 1; // 1通过 2不通过
            ZLDC.Topo.BLL.Estate.HousingBLL.HousingCheckStatus2(id, status);

            // 更新缓存
            if (id > 0)
            {
                _Cache.Remove(CacheConst.CACHE_HOUSING_DETAIL_JSON + id.ToString());
                _Cache.Remove(CacheConst.CACHE_HOUSING_DETAIL_INFO + id.ToString());
                _Cache.RemoveLike(CacheConst.CACHE_HOUSING_FOLLOW_JSON + id);
            }

        }

    }
}
